import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
testcase = "dbshop-010处理退货"

firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
rootPath=get_pro_rootpath() #获取项目的绝对路径
filePath=rootPath+r'\public\orderID.txt' #拼接文件路径
orderNo=readFile(filePath) #读取文件中的订单编号



# 1.点击销售管理支付记录。
DBshopEnterMenu2(firefox,'销售管理','退货管理')
time.sleep(5)

# 轴定位 根据订单编号 点击
firefox.find_element_by_xpath('//td[text()="%s"]/following-sibling::td[5]/a'%orderNo).click()
s = firefox.find_element_by_xpath("//body").text
print(s)
l="订单总额\:\￥"
r="\nCopyright"
price =reGetString(s,l,r)
print(price)

# 查询订单号 ，输入退款金额
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys(price)
firefox.find_element_by_xpath('//button[@class="btn btn-small btn-primary"]').click()
firefox.close()

firefox= openBrowser(url)
# 点击我的订单
firefox.find_element_by_link_text("我的订单").click()
# 点击退货订单
firefox.find_element_by_xpath('//a[contains(text(),"退货订单)]').click()
time.sleep(5)

# 搜索订单
firefox.find_element_by_xpath('//input[@name="search_order_sn"]').send_keys(orderNo)
firefox.find_element_by_xpath('//button[@class="btn btn-small btn-primary"]').click()

# 断言 ，看订单是否存在
try:
    firefox.find_element_by_link_text(orderNo).is_displayed()
    writeLog("%s 测试通过" % testcase)
except:
    writeLog("%s 测试失败" % testcase)
    getPhoto(firefox)
firefox.quit()

